# Contributor: Fabricio Silva <hi@fabricio.dev>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=jackett
pkgver=0.22.549
pkgrel=0
pkgdesc="API Support for your favorite torrent trackers"
url="https://github.com/Jackett/Jackett"
arch="x86_64 aarch64 armv7"
license="GPL-3.0-only"
options="net !check" # no tests
depends="dotnet8-runtime"
makedepends="dotnet8-sdk"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/Jackett/Jackett/archive/refs/tags/v$pkgver.tar.gz
	jackett.initd
	jackett.confd
	"
builddir="$srcdir/Jackett-$pkgver/src"

prepare() {
	default_prepare

	# replace version info
	local buildprops=Jackett.Common/Jackett.Common.csproj
	sed -i -e "s/<Version>[0-9.*]\+<\/Version>/<Version>$pkgver<\/Version>/g" "$buildprops"
}

build() {
	dotnet publish Jackett.Server \
		--framework "net8.0" \
		--no-self-contained \
		--use-current-runtime \
		--configuration Release \
		--output publish

	# remove erroneously installed mono runtime library
	rm -rf publish/libMono.Unix.so
}

package() {
	mkdir -p "$pkgdir"/usr/lib
	cp -af publish "$pkgdir"/usr/lib/jackett

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
5119a133ebee6984d5a469fd60e83f18775c03e89053f26d31d55ddd4e3cd36d01a5f47fe171f969bbc2a9d93b6fff325c82375b08878f86673d02e2907e0590  jackett-0.22.549.tar.gz
71dc80cee88d0166bcd18a784e9beda0eda6f5b34cf256f65a364375e6407bcf0f6b3eedadc2d1148d48acff9e5489134c28462d92a07c98fb5363e6adf4154a  jackett.initd
c9963ddf11e8ebb35891172226c2486d56f9bafdf7e40c99fab5d34489a5afc37902af55d9cf097d5f9cb713a6bff8b5ce4d04c3d4553b647315ba0d847dbc20  jackett.confd
"
